package com.smag.echarts.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.smag.common.core.domain.AjaxResult;
import com.smag.common.utils.StringUtils;
import com.smag.echarts.domain.EchartsConeEconomy;
import com.smag.echarts.service.EchartsConeEconomyService;
import com.smag.echarts.mapper.EchartsConeEconomyMapper;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
* @author hzqhzq
* @description 针对表【echarts_cone_economy】的数据库操作Service实现
* @createDate 2023-04-21 17:47:22
*/
@Service
public class EchartsConeEconomyServiceImpl extends ServiceImpl<EchartsConeEconomyMapper, EchartsConeEconomy>
    implements EchartsConeEconomyService{

    @Override
    public AjaxResult getEconomyList() {
        List<EchartsConeEconomy> list = list();
        EchartsConeEconomy[] echartsConeEconomies = list.toArray(new EchartsConeEconomy[0]);
        Arrays.sort(echartsConeEconomies, (o1, o2) -> o2.getValue().compareTo(o1.getValue()));
        list = Arrays.asList(echartsConeEconomies);
        return AjaxResult.success(list);
    }

    @Override
    public List<EchartsConeEconomy> selectEchartsConeEconomyList(EchartsConeEconomy echartsConeEconomy) {
        LambdaQueryWrapper<EchartsConeEconomy> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StringUtils.isNotEmpty(echartsConeEconomy.getName()),EchartsConeEconomy::getName,echartsConeEconomy.getName());
        queryWrapper.like(ObjectUtils.isNotNull(echartsConeEconomy.getValue()),EchartsConeEconomy::getValue,echartsConeEconomy.getValue());
        return list(queryWrapper);
    }

    @Override
    public AjaxResult selectEchartsConeEconomyById(Long id) {
        return AjaxResult.success(getById(id));
    }

    @Override
    public AjaxResult insertEchartsConeEconomy(EchartsConeEconomy echartsConeEconomy) {
        if (save(echartsConeEconomy)) {
            return AjaxResult.success();
        }
        return AjaxResult.error();
    }

    @Override
    public AjaxResult updateEchartsConeEconomy(EchartsConeEconomy echartsConeEconomy) {
        if (updateById(echartsConeEconomy))
            return AjaxResult.success();
        return AjaxResult.error();
    }

    @Override
    public AjaxResult deleteEchartsConeEconomyByIds(Long[] ids) {
        if (getBaseMapper().deleteEchartsConeEconomyBatchByIds(ids) > 0) {
            return AjaxResult.success();
        }
        return AjaxResult.error();
    }
}




